package com.itheima.a05tcpdemo1;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //服务器
        //创建服务器对象并指定端口
        ServerSocket ss = new ServerSocket(6666);
        //监听客户端连接,返回一个Socket对象
        Socket socket = ss.accept();
        //通过Socket对象,获取输入流,读数据
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int i;
        while ((i = isr.read()) != -1) {
            System.out.print((char) i);
        }
        //释放资源
//        isr.close();
        socket.close();
    }
}
